<template>
        <el-container class="home_container">
            <!-- 头部区域 -->
            <el-header>
            <div>
                <img src="../assets/logo.png" alt="">
                <span>晚安小雯的后台管理系统</span>
            </div>
            <el-button type="info" round @click="logout">退出</el-button>
            </el-header>
          <!-- 主题区域 -->
            <el-container>
            <!-- 侧边栏 -->
            <el-aside  :width="isCollapse? '64px':'200px'">
                <!-- 折叠按钮 -->
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                     <el-menu 
                        :default-active="activePath"
                        :router="true"
                        :collapse="isCollapse"
                        :collapse-transition="false"
                        :unique-opened="true"
                        background-color="#333744"
                        text-color="#fff"
                        active-text-color="#ffd04b">
                        <!-- 一级导航 -->
                        <el-submenu :index="item.pttype_id +''" v-for="(item,key) in menuList" :key="item.pttype_id">
                            <!-- 一级导航的横板区域 -->
                            <template slot="title">
                                <!-- 图标 -->
                            <i :class="iconsObj[key]"></i>
                            <!-- 文本 -->
                            <span>{{item.pttype_name}}</span>
                            </template>
                            <!-- 二级导航 -->
                            <el-menu-item 
                            @click="saveActivePath(subItem.path)"
                            :index="subItem.path"
                             v-for="subItem in item.search" 
                             :key="subItem.pttype_id">
                                <template slot="title">
                                <!-- 图标 -->
                                <i class="el-icon-location"></i>
                                <!-- 文本 -->
                                <span>{{subItem.pttype_name}}</span>
                            </template>
                            </el-menu-item>                           
                            </el-submenu>
                        </el-menu>
            </el-aside>
        <!-- 右侧内容 -->
            <el-main>
                <router-view></router-view>
            </el-main>
            
        </el-container>
        
    </el-container>
</template>

<script>
export default {
    data(){
        return{
            menuList:[],
            isCollapse:false,
            iconsObj:[
                "el-icon-cold-drink",
                "el-icon-knife-fork",
                "el-icon-hot-water"
            ],
            activePath:""
        }
    },
    created(){
        this.getMenuList();
        this.activePath = window.sessionStorage.getItem("activePath");
        
    },
    methods:{
        saveActivePath(activePath){
            window.sessionStorage.setItem("activePath",activePath);
            this.activePath = activePath
        },
        toggleCollapse(){
            this.isCollapse= !this.isCollapse;
        },
        getMenuList(){
            this.$axios.get("cooking/pttype").then(res =>{
                // console.log(res)
                if(res.data.code !=1) return this.$message.error(res.data.msg);
                this.menuList = res.data.data;
                console.log(res.data.data)
            })
        },
        logout(){
            //清空sessionStorage
            window.sessionStorage.clear();
            //跳转登录页面
            this.$router.push('/login');
        }
    }
}
</script>

<style lang="less" scoped>
    .home_container{
        height: 100%;
    }
    .el-header{
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        font-size: 20px;
        div{
            display: flex;
            align-items: center;
            span{
                margin-left: 15px;
            }
            img{
                width: 50px;
                height: 50px;
                border-radius: 50%;
                background-color: #eee;
            }
        }
    }
    .el-aside{
        background-color: #333744;
        .el-menu{
            border-right: none;
        }
    }
    .el-main{
        background-color: #eaedf1;
    }
    .toggle-button{
        background-color: #4a5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2;
        cursor: pointer;
    }
    
</style>